//
//  Alter.swift
//  CustomAlter
//
//  Created by slience on 2019/7/25.
//  Copyright © 2019 shehuiren. All rights reserved.
//

import UIKit

final class Alter{
    
    class Builder{
        
        private var title: String?
        private var content: String?
        private var attributedContent: NSAttributedString?
        private var noText: String?
        private var yesText: String?
        private var isCancelOnTouchOutside: Bool = false
        private var noAction: (() -> Void)?
        private var yesAction: (() -> Void)?
        
        
        func title(_ title: String) -> Builder {
            self.title = title
            return self
        }
        
        func content(_ content: String) -> Builder {
            self.content = content
            return self
        }
        
        func attributedContent(_ content: NSAttributedString) -> Builder {
            self.attributedContent = content
            return self
        }
        
        func noText(_ text: String) -> Builder {
            self.noText = text
            return self
        }
        
        func yesText(_ text: String) -> Builder {
            self.yesText = text
            return self
        }
        
        func cancelOnTouchOutside(_ cancel: Bool) -> Builder {
            self.isCancelOnTouchOutside = cancel
            return self
        }
        
        func noAction(_ action: @escaping (()->Void)) -> Builder {
            self.noAction = action
            return self
        }
        
        func yesAction(_ action: @escaping (()->Void)) -> Builder {
            self.yesAction = action
            return self
        }
        
        
        func build(){
            
            let  alert = AlterView()
            
            alert.title = title
            alert.content = content
            alert.noText = noText
            alert.yesText = yesText
            
            alert.noAction = noAction
            alert.yesAction = yesAction
            
            if let windows = UIApplication.shared.keyWindow{
                
                alert.frame = windows.bounds
                
                windows.addSubview(alert)
            }
        }
        
        
    }
    
    static func builder()->Builder{
        
        return Builder()
    }
}
